<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>NumPy benchmarks &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="_static/css/spc-extend.css">
    <link rel="stylesheet" href="_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    <script type="text/javascript" src="_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="about.html" >
    <link rel="index" title="Index" href="genindex.html" >
    <link rel="search" title="Search" href="search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="index.html" >
    <link rel="up" title="Contributing to NumPy" href="dev/index.html" >
    <link rel="next" title="NumPy C Style Guide" href="dev/style_guide.html" >
    <link rel="prev" title="Development workflow" href="dev/development_workflow.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="index.html">
      <img border=0 alt="NumPy" src="_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="dev/index.html" accesskey="U">Contributing to NumPy</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="dev/style_guide.html" title="NumPy C Style Guide"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="dev/development_workflow.html" title="Development workflow"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">NumPy benchmarks</a><ul>
<li><a class="reference internal" href="#usage">Usage</a></li>
<li><a class="reference internal" href="#writing-benchmarks">Writing benchmarks</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="dev/development_workflow.html"
                        title="previous chapter">Development workflow</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="dev/style_guide.html"
                        title="next chapter">NumPy C Style Guide</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-benchmarks">
<h1>NumPy benchmarks<a class="headerlink" href="#numpy-benchmarks" title="Permalink to this headline">¶</a></h1>
<p>Benchmarking NumPy with Airspeed Velocity.</p>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>Airspeed Velocity manages building and Python virtualenvs by itself,
unless told otherwise. Some of the benchmarking features in
<code class="docutils literal notranslate"><span class="pre">runtests.py</span></code> also tell ASV to use the NumPy compiled by
<code class="docutils literal notranslate"><span class="pre">runtests.py</span></code>. To run the benchmarks, you do not need to install a
development version of NumPy to your current Python environment.</p>
<p>Run a benchmark against currently checked out NumPy version (don’t
record the result):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">runtests</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">bench</span> <span class="n">bench_core</span>
</pre></div>
</div>
<p>Compare change in benchmark results to another version:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">runtests</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">bench</span><span class="o">-</span><span class="n">compare</span> <span class="n">v1</span><span class="o">.</span><span class="mf">6.2</span> <span class="n">bench_core</span>
</pre></div>
</div>
<p>Run ASV commands (record results and generate HTML):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">benchmarks</span>
<span class="n">asv</span> <span class="n">run</span> <span class="o">--</span><span class="n">skip</span><span class="o">-</span><span class="n">existing</span><span class="o">-</span><span class="n">commits</span> <span class="o">--</span><span class="n">steps</span> <span class="mi">10</span> <span class="n">ALL</span>
<span class="n">asv</span> <span class="n">publish</span>
<span class="n">asv</span> <span class="n">preview</span>
</pre></div>
</div>
<p>More on how to use <code class="docutils literal notranslate"><span class="pre">asv</span></code> can be found in <a class="reference external" href="https://asv.readthedocs.io/">ASV documentation</a>
Command-line help is available as usual via <code class="docutils literal notranslate"><span class="pre">asv</span> <span class="pre">--help</span></code> and
<code class="docutils literal notranslate"><span class="pre">asv</span> <span class="pre">run</span> <span class="pre">--help</span></code>.</p>
</div>
<div class="section" id="writing-benchmarks">
<h2>Writing benchmarks<a class="headerlink" href="#writing-benchmarks" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference external" href="https://asv.readthedocs.io/">ASV documentation</a> for basics on how to write benchmarks.</p>
<p>Some things to consider:</p>
<ul class="simple">
<li><p>The benchmark suite should be importable with any NumPy version.</p></li>
<li><p>The benchmark parameters etc. should not depend on which NumPy version
is installed.</p></li>
<li><p>Try to keep the runtime of the benchmark reasonable.</p></li>
<li><p>Prefer ASV’s <code class="docutils literal notranslate"><span class="pre">time_</span></code> methods for benchmarking times rather than cooking up
time measurements via <code class="docutils literal notranslate"><span class="pre">time.clock</span></code>, even if it requires some juggling when
writing the benchmark.</p></li>
<li><p>Preparing arrays etc. should generally be put in the <code class="docutils literal notranslate"><span class="pre">setup</span></code> method rather
than the <code class="docutils literal notranslate"><span class="pre">time_</span></code> methods, to avoid counting preparation time together with
the time of the benchmarked operation.</p></li>
<li><p>Be mindful that large arrays created with <code class="docutils literal notranslate"><span class="pre">np.empty</span></code> or <code class="docutils literal notranslate"><span class="pre">np.zeros</span></code> might
not be allocated in physical memory until the memory is accessed. If this is
desired behaviour, make sure to comment it in your setup function. If
you are benchmarking an algorithm, it is unlikely that a user will be
executing said algorithm on a newly created empty/zero array. One can force
pagefaults to occur in the setup phase either by calling <code class="docutils literal notranslate"><span class="pre">np.ones</span></code> or
<code class="docutils literal notranslate"><span class="pre">arr.fill(value)</span></code> after creating the array,</p></li>
</ul>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>